package com.se.config;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.FastHashMap;
import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.lang.StringUtils;

public class CommonsConfigurationPreferences
  implements Preferences
{
  private FastHashMap configurationMap = new FastHashMap();
  private CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
  private Configuration virtualConfiguration;
  private boolean autoCommit = true;

  protected void addConfiguration(String paramString, XMLConfiguration paramXMLConfiguration)
  {
    this.configurationMap.setFast(false);
    this.configurationMap.put(paramString, paramXMLConfiguration);
    this.configurationMap.setFast(true);
    this.compositeConfiguration.addConfiguration(paramXMLConfiguration);
  }

  protected void setVirtualConfiguration(Configuration paramConfiguration)
  {
    this.virtualConfiguration = paramConfiguration;
    this.compositeConfiguration.addConfiguration(paramConfiguration);
  }

  public Configuration getVirtualConfiguration()
  {
    return this.virtualConfiguration;
  }

  public void addProperty(String paramString, Object paramObject)
    throws ConfigurationException
  {
    XMLConfiguration localXMLConfiguration = getConfiguration(paramString);
    localXMLConfiguration.addProperty(paramString, paramObject);
    if (this.autoCommit)
      localXMLConfiguration.save();
  }

  public Object get(String paramString)
  {
    return this.compositeConfiguration.getProperty(paramString);
  }

  public Object get(String paramString, Object paramObject)
  {
    Object localObject = get(paramString);
    if (localObject == null)
      localObject = paramObject;
    return localObject;
  }

  public double getDouble(String paramString)
  {
    return this.compositeConfiguration.getDouble(paramString);
  }

  public long getLong(String paramString)
  {
    return this.compositeConfiguration.getLong(paramString);
  }

  public int getInt(String paramString)
  {
    return this.compositeConfiguration.getInt(paramString);
  }

  public String getString(String paramString)
  {
    return this.compositeConfiguration.getString(paramString);
  }

  public void remove(String paramString)
    throws ConfigurationException
  {
    XMLConfiguration localXMLConfiguration = getConfiguration(paramString);
    localXMLConfiguration.setProperty(paramString, "");
    if (this.autoCommit)
      localXMLConfiguration.save();
  }

  public void setProperty(String paramString, Object paramObject)
    throws ConfigurationException
  {
    XMLConfiguration localXMLConfiguration = getConfiguration(paramString);
    localXMLConfiguration.setProperty(paramString, paramObject);
    if (this.autoCommit)
      localXMLConfiguration.save();
  }

  private XMLConfiguration getConfiguration(String paramString)
  {
    XMLConfiguration localXMLConfiguration = null;
    String[] arrayOfString = StringUtils.split(paramString, ".");
    if ((arrayOfString == null) || (arrayOfString.length < 2))
      return null;
    String str = arrayOfString[0] + "-" + arrayOfString[1] + ".xml";
    localXMLConfiguration = (XMLConfiguration)this.configurationMap.get(str);
    return localXMLConfiguration;
  }

  public void setAutoCommit(boolean paramBoolean)
  {
    this.autoCommit = paramBoolean;
  }

  public double getDouble(String paramString, double paramDouble)
  {
    return this.compositeConfiguration.getDouble(paramString, paramDouble);
  }

  public int getInt(String paramString, int paramInt)
  {
    return this.compositeConfiguration.getInt(paramString, paramInt);
  }

  public long getLong(String paramString, long paramLong)
  {
    return this.compositeConfiguration.getLong(paramString, paramLong);
  }

  public String getString(String paramString1, String paramString2)
  {
    return this.compositeConfiguration.getString(paramString1, paramString2);
  }

  public boolean getBoolean(String paramString, boolean paramBoolean)
  {
    return this.compositeConfiguration.getBoolean(paramString, paramBoolean);
  }

  public List getKeyList(String paramString)
  {
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = this.compositeConfiguration.getKeys(paramString);
    String str = "";
    while (localIterator.hasNext())
    {
      str = (String)localIterator.next();
      str = str.substring(str.indexOf(paramString) + paramString.length() + 1);
      if (str.indexOf(".") > 0)
        str = paramString + "." + str.substring(0, str.indexOf("."));
      else
        str = paramString + "." + str;
      if (!localArrayList.contains(str))
        localArrayList.add(str);
    }
    return localArrayList;
  }

  public boolean getBoolean(String paramString)
  {
    return this.compositeConfiguration.getBoolean(paramString);
  }

  public List getList(String paramString)
  {
    return this.compositeConfiguration.getList(paramString);
  }
}

/* Location:           D:\DevApp\workspace\DevKsnetWeb9.3\WebContent\WEB-INF\lib\netville-2.2.3.jar
 * Qualified Name:     netville.config.CommonsConfigurationPreferences
 * JD-Core Version:    0.6.2
 */